﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Configuration;
using System.ServiceModel;
using Ninject;
using MapReduceLib.Contracts;
using MapReduceLib;

namespace SlaveNode
{
    class Program
    {
        private static ILog Log = LogManager.GetLogger(typeof(Program));

        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            Log.DebugFormat("Starting slave node on port {0}...", ConfigurationManager.AppSettings["StartupPort"]);

            NetTcpBinding binding = WCFUtils.GetDefaultBinding();

            // DI Container bootup...
            IKernel kernel = new StandardKernel(new SlaveModule());

            ServiceHost serviceHostJobManager = new ServiceHost(kernel.Get<ITaskExecuter>());
            Log.DebugFormat("Publishing TaskExecuter service at URL net.tcp://localhost:{0}/TaskExecuter/", ConfigurationManager.AppSettings["StartupPort"]);
            serviceHostJobManager.AddServiceEndpoint(typeof(ITaskExecuter), binding, string.Format("net.tcp://localhost:{0}/TaskExecuter/", ConfigurationManager.AppSettings["StartupPort"]));
            serviceHostJobManager.Open();

            Log.Debug("Slave node initialization complete...");
            Console.ReadLine();
        }
    }
}
